
/**
 * @desc 手机号段前缀
 */
const phonePrefixes = [
    '130', '131', '132', '133', '134', '135', '136', '137', '138', '139',
    '145', '147', '150', '151', '152', '153', '155', '156', '157', '158', '159',
    '166', '170', '171', '172', '173', '175', '176', '177', '178', '180', '181',
    '182', '183', '184', '185', '186', '187', '188', '189', '198', '199'
];

/**
 * @desc 随机生成手机号段前缀
 */
function randomPhonePrefix() {
    const prefix = phonePrefixes[Math.floor(Math.random() * phonePrefixes.length)];
    return prefix;
}

/**
 * 生成手机号码
 * @param {string} phonePrefixe 手机号段前缀 130-199 之间
 */
function randomPhone(phonePrefixe = null) {
    // 随机选择一个前缀
    const prefix = phonePrefixe ? phonePrefixe : randomPhonePrefix();

    // 生成后8位随机数字
    let suffix = '';
    for (let i = 0; i < 8; i++) {
        suffix += Math.floor(Math.random() * 10);
    }

    // 返回完整的手机号码
    return prefix + suffix;
}

export { phonePrefixes, randomPhonePrefix, randomPhone };